<template>
<div class="panel">
  <blockquote class="head" v-if="title || $slots.head" :style="{borderLeft: `5px solid ${color}`}">
    <div class="title" :style="{maxWidth:(typeof (this.$slots.head) === 'undefined' ? null : `${width}px`)}" :title="title"> {{title}}</div>
    <div :class="{'title-slot':title?true:false}">
      <slot name="head"></slot>
    </div>
  </blockquote>
  <div class="body">
    <slot></slot>
  </div>
  <div class="more" v-if="isShowMore">
    <slot name="more"></slot>
  </div>
  <div class="morebar" v-if="$slots.more">
    <vui-button icon="ios-arrow-down" type="text" v-if="!isShowMore" @click="onShowMore">更多</vui-button>
    <vui-button icon="ios-arrow-up" type="text" v-if="isShowMore" @click="onShowMore"></vui-button>
  </div>
</div>
</template>

<script>
export default {
  name: 'vuiPanel',
  data() {
    return {
      isShowMore: false
    }
  },
  props: {
    title: {
      type: String,
      default: ''
    },
    color: {
      type: String,
      default: '#4aa3df'
    },
    width: {
      type: [String, Number],
      default: '400'
    }
  },
  methods: {
    onShowMore() {
      this.isShowMore = !this.isShowMore
    }
  }
}
</script>

<style scoped>
.panel {
  margin: 0 0 15px 0;
  position: relative;
}

.panel .head {
  color: #666;
  font-size: 14px;
  line-height: 1.5;
  margin: 5px 0;
  padding: 5px 5px 3px 10px;
}

.panel .body,
.panel .more {
  padding: 0 5px 0 20px;
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
}

.panel .morebar {
  text-align: center;
  cursor: pointer;
  padding: 0;
}

.panel .morebar .ivu-btn {
  color: #999;
  font-size: 10px;
  padding-bottom: 0;
  padding-top: 0;
}

.title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.title-slot {
  position: absolute;
  top: 6px;
  right: 0px;
}
</style>
